package com.wpen.unit.web.controller.job;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wpen.unit.service.job.AgentExecLogService;
import com.wpen.unit.service.job.AgentRegistryService;
import com.wpen.unit.service.job.BatchExecLogService;
import com.wpen.unit.service.job.BatchInfoService;
import com.wpen.unit.service.job.JobExec1LogService;
import com.wpen.unit.service.job.TaskExecLogService;
import com.wpen.unit.service.job.TaskInfoService;
import com.wpen.unit.web.dto.job.StatRequest;
import com.wpen.unit.web.dto.job.StatResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 统计
 * 
 * @author pg
 *
 */
@Tag(name = "统计服务接口")
@RestController
@RequestMapping("/api")
public class StatController {
	@Autowired
	private BatchInfoService batchInfoService;
	@Autowired
	private TaskInfoService taskInfoService;
	@Autowired
	private AgentRegistryService agentRegistryService;
	@Autowired
	private BatchExecLogService batchExecLogService;
	@Autowired
	private TaskExecLogService taskExecLogService;
	@Autowired
	private JobExec1LogService jobExec1LogService;
	@Autowired
	private AgentExecLogService agentExecLogService;

	@Operation(summary = "批次-统计查询")
	@PostMapping(value = "/stat/batch-stat", produces = MediaType.APPLICATION_JSON_VALUE)
	public StatResponse statCountBatch(@RequestBody @Valid StatRequest statRequest) {
		return batchInfoService.statCountBatch(statRequest);
	}
	
	@Operation(summary = "任务-统计查询")
	@PostMapping(value = "/stat/task-stat", produces = MediaType.APPLICATION_JSON_VALUE)
	public StatResponse statCountTask(@RequestBody @Valid StatRequest statRequest) {
		return taskInfoService.statCountTask(statRequest);
	}

	@Operation(summary = "执行器-统计查询")
	@PostMapping(value = "/stat/agent-stat", produces = MediaType.APPLICATION_JSON_VALUE)
	public StatResponse statCountAgent(@RequestBody @Valid StatRequest statRequest) {
		return agentRegistryService.statCountAgent(statRequest);
	}
	
	@Operation(summary = "今日批次-统计查询")
	@PostMapping(value = "/stat/today-batch-exec", produces = MediaType.APPLICATION_JSON_VALUE)
	public StatResponse statTodayBatchExec(@RequestBody @Valid StatRequest statRequest) {
		return batchExecLogService.statTodayBatchExec(statRequest);
	}
	
	@Operation(summary = "今日任务-统计查询")
	@PostMapping(value = "/stat/today-task-exec", produces = MediaType.APPLICATION_JSON_VALUE)
	public StatResponse statTodayTaskExec(@RequestBody @Valid StatRequest statRequest) {
		return taskExecLogService.statTodayTaskExec(statRequest);
	}
	
	@Operation(summary = "今日作业-统计查询")
	@PostMapping(value = "/stat/today-job-exec", produces = MediaType.APPLICATION_JSON_VALUE)
	public StatResponse statTodayJobExec(@RequestBody @Valid StatRequest statRequest) {
		return jobExec1LogService.statTodayJobExec(statRequest);
	}
	
	@Operation(summary = "今日执行器-统计查询")
	@PostMapping(value = "/stat/today-agent-exec", produces = MediaType.APPLICATION_JSON_VALUE)
	public StatResponse statTodayAgentExec(@RequestBody @Valid StatRequest statRequest) {
		return agentExecLogService.statTodayAgentExec(statRequest);
	}
	
}
